package com.ewhale.feitengguest.presenter.shop.mine

import com.ewhale.feitengguest.api.ApiHelper
import com.ewhale.feitengguest.dto.ShopBillDetailDto
import com.ewhale.feitengguest.dto.ShopBillDto
import com.ewhale.feitengguest.dto.ShopWalletDto
import com.ewhale.feitengguest.view.shop.mine.ShopWalletView
import com.simga.library.base.IPresenter
import com.simga.library.http.APIException

/**
 * 作者：SimGa
 * 日期：2020/1/6
 * 时间：10:08
 * 包名：com.ewhale.feitengguest.presenter.shop.mine
 */
class ShopWalletPresenter :IPresenter(){


    fun getShopWallet(){
        mView.showProLoading()
        request(1,ApiHelper.USER_API.shopWalletAndStatus,null)
    }
    fun getShopBillList(pageNumber: Int,status: Int) {
        request(2,ApiHelper.USER_API.getShopWater(pageNumber,10,status),null)
    }
    fun getShopBillDetail(billId: Int?) {
        mView.showProLoading()
        request(3,ApiHelper.USER_API.getShopWaterDetail(billId!!),null)
    }
    override fun <T : Any?> onNext(postCode: Int, result: T?, data: Any?) {
        super.onNext(postCode, result, data)
        when(postCode){
            1->(mView as ShopWalletView).showWallet(result as ShopWalletDto)
            2->(mView as ShopWalletView).showShopBillList(result as List<ShopBillDto>)
            3->(mView as ShopWalletView).showShopBillDetail(result as ShopBillDetailDto)
        }
    }

    override fun otherException(postCode: Int, data: Any?, e: APIException?) {
        super.otherException(postCode, data, e)
        mView.showErrorMessage(postCode,e!!.code,e.displayMessage)
    }

}
